import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
import './vant/index.js'
import './element-ui/index.js'
import './utils/tool.js'
import { initWebSocket } from './utils/websocket'

Vue.config.productionTip = false

// WebSocket初始化标志
let isWebSocketInitialized = false
// 在路由守卫中初始化WebSocket连接
router.beforeEach((to, from, next) => {
  if (!isWebSocketInitialized && !to.path.includes('/admin')) {
    initWebSocket()
    isWebSocketInitialized = true // 设置标志为已初始化
  }
  next()
})

new Vue({
  router,
  render: (h) => h(App)
}).$mount('#app')
